﻿using PLCWpfTest.Views;
using System.Windows;
using YWM;
using YWM.Localization;

namespace PLCWpfTest.Common.Extensions
{
    public static class MessageBoxExtensions
    {
        public static void ShowInfo(this object obj, string text)
        {
            ILocalizationManager lang = YApp.Resolve<ILocalizationManager>();
            obj.ShowBox(lang[text], lang["提示"], MessageBoxImage.Information);
            //MessageBox.Show(lang[text], lang["提示"], MessageBoxButton.OK, MessageBoxImage.Information);
        }

        public static void ShowWarning(this object obj, string text)
        {
            ILocalizationManager lang = YApp.Resolve<ILocalizationManager>();
            obj.ShowBox(lang[text], lang["警告"], MessageBoxImage.Warning);
            //MessageBox.Show(lang[text], lang["警告"], MessageBoxButton.OK, MessageBoxImage.Warning);
        }

        public static void ShowError(this object obj, string text)
        {
            ILocalizationManager lang = YApp.Resolve<ILocalizationManager>();
            obj.ShowBox(lang[text], lang["错误"], MessageBoxImage.Error);
            //MessageBox.Show(lang[text], lang["错误"], MessageBoxButton.OK, MessageBoxImage.Error);
        }

        public static MessageBoxResult ShowQuestion(this object obj, string text)
        {
            ILocalizationManager lang = YApp.Resolve<ILocalizationManager>();
            return obj.ShowBox(lang[text], lang["询问"], MessageBoxImage.Question, true);
            //return MessageBox.Show(lang[text], lang["询问"], MessageBoxButton.OKCancel, MessageBoxImage.Question);
        }

        private static MessageBoxResult ShowBox(this object obj, string text, string caption, MessageBoxImage icon, bool isShowCancel = false)
        {
            ConfirmDialog dialog = new ConfirmDialog(text, caption, icon, isShowCancel);
            bool rs = dialog.ShowDialog().Value;
            return rs ? MessageBoxResult.OK : MessageBoxResult.Cancel;
        }
    }
}
